<!--开票明细-->
<template>
  <div>
    <f-search-form ref='search' :more='true' @searchHandler='searchHandler' style='margin-bottom: 10px' @exportHandler='exportHandler' :show-export-btn='true' :exportUrl='api.bhid.exportUrl'>
      <f-search-form-item label='单号' name='orderNo' />
      <f-search-form-item label='业务员' name='saleManName' />
      <f-search-form-item label='发货日期' type='range' name='beginDate' />
    </f-search-form>
    <f-table ref='table'
             rowKey='invoiceDetailsId'
             :showSetting='false'
             setting-key='invoiceDetailsId_kp_details'
             :tableColumns='columns'
             :scroll='{x:true}'
             :showMultipleBtn='false'
             :showPagination='false'
             :showTotal='true'
             :multiple='false'
             handler='hyInvoiceDetailsPageListHandler'
             :operator='operator'
             :autoLoad='false'
             :params='queryParam'
             @onSuccess='onSuccess'
             :api='api.bhid.list'>
       <span slot='drugType' slot-scope='text, record, index'>
           <a-tag color='#2db7f5' v-if='text=="ZY"'>自营</a-tag>
           <a-tag color='#FF0000' v-if='text=="ZS"'>招商</a-tag>
       </span>
      <span slot='sendType' slot-scope='text, record, index'>
           <a-tag color='#2db7f5' v-if='text==1'>现款</a-tag>
           <a-tag color='#FF0000' v-if='text==2'>预收款</a-tag>
           <a-tag color='#87d068' v-if='text==3'>资保金</a-tag>
           <a-tag color='purple' v-if='text==4'>全额资信</a-tag>
       </span>
      <span slot='action' slot-scope='text, record'>
         <template v-if='record.rowIndex!="合计"'>
            <a href='javascript:;' @click='$refs.orderDetailsDrawer.showDrawer(record)'>详情</a>
          </template>
        </span>
    </f-table>
    <a-divider orientation='left'>资金支付明细
    </a-divider>
    <f-table ref='settleTable' rowKey='paymentId' :operator='operator2' :showSetting='false' :tableColumns='settleColumns' :scroll='{x:true}' handler='hySettlePaymentPageListHandler' :showPagination='false' :showMultipleBtn='false' :multiple='false' :params='queryParam2' :showTotal='true' :autoLoad='false' :api='api.payment.list' style='margin-bottom: 10px'>
       <span slot='invoiceType' slot-scope='text, record, index'>
            <a-tag color='#87d068' v-if='text==1'>普票</a-tag>
            <a-tag color='#108ee9' v-if='text==2'>专票</a-tag>
       </span>
      <span slot='paymentState' slot-scope='text, record, index'>
            <a-tag color='#87d068' v-if='text==0'>未支付</a-tag>
            <a-tag color='#108ee9' v-if='text==2'>已支付</a-tag>
       </span>
      <span slot='action' slot-scope='text, record' v-if='record.rowIndex!="合计"'>
          <template>
            <a @click='$refs.settlePayDrawer.showDrawer(record)' v-if='invoiceData.taskDefinitionKey=="Activity_settlePay"'>支付</a>
            <a-divider type='vertical' v-if='invoiceData.taskDefinitionKey=="Activity_settlePay"' />
            <a @click='$refs.saleManSettleDrawer.showDrawer(record)'>明细</a>
            <a-divider type='vertical' />
          </template>
           <a-dropdown>
            <a class='ant-dropdown-link'>更多 <a-icon type='down' /></a>
            <a-menu slot='overlay'>
            <a-menu-item>
                <a href='javascript:;' @click='printOrder(record)'>资金支付单</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
    </f-table>
    <hy-order-details-drawer ref='orderDetailsDrawer'></hy-order-details-drawer>
    <sale-man-settle-details-drawer ref='saleManSettleDrawer'></sale-man-settle-details-drawer>
    <print-modal ref='printModal'></print-modal>
    <settle-pay-drawer ref='settlePayDrawer'></settle-pay-drawer>
  </div>
</template>
<script>
import api from "../../../../js/api"
import HyOrderDetailsDrawer from "@/views/module/haiying/order/details/hyorder_details_drawer"
import SaleManSettleDetailsDrawer from "@/views/module/haiying/tasktodo/payment/components/saleman/saleman_settle_details_drawer"
import PrintModal from "@/views/module/haiying/print/print_modal"
import SettlePayDrawer from "@/views/module/haiying/tasktodo/payment/components/pay/settle_pay_drawer"


export default {
  name: "InvoiceDetails",
  components: { SettlePayDrawer, PrintModal, SaleManSettleDetailsDrawer, HyOrderDetailsDrawer },
  props: {
    columns: {
      type: Array,
      default: []
    },
    invoiceData: {
      type: Object,
      default: null
    }
  },
  data() {
    let me = this
    //操作按钮
    let operator = []
    let operator2 = []
    operator2.push({
      name: "导出",
      that: this,
      handler: (table, that) => {
        this.$refs.settleTable.tableExport('bus/payment/hyExport')
      }
    })
    return {
      api: Object.assign(api, this.api),
      multiple: false,
      deptId: "",
      visible: false,
      maxAmount: 0,
      //列表初始化查询参数
      queryParam: {
        fileName: "结算开票明细-"
      },
      //列表初始化查询参数
      queryParam2: {
        fileName: "资金支付明细"
      },
      returnCustomBond: 0,
      selectIds: "",
      params1: {
        deptId: ""
      },
      dataSource: [],
      settleColumns: [
        {
          title: "序号",
          width: "60px",
          align: "center",
          customRender: function(text, record, index) {
            return (record.rowIndex !== "合计") ? (parseInt(index) + 1) : record.rowIndex
          }
        },
        {
          title: "开票日期",
          align: "center",
          width: "100px",
          dataIndex: "amountDate"
        },
        {
          title: "单号",
          align: "center",
          width: "130px",
          dataIndex: "paymentNo"
        },
        {
          title: "业务员",
          align: "center",
          width: "120px",
          ellipsis: true,
          dataIndex: "saleManName"
        },
        {
          title: "结算金额",
          align: "left",
          width: "80px",
          needTotal: true,
          type: 10,
          dataIndex: "amount"
        },
        {
          title: "开票金额",
          align: "left",
          needTotal: true,
          width: "80px",
          type: 10,
          dataIndex: "invoiceAmount"
        },
        {
          title: "不含税金额",
          align: "left",
          width: "90px",
          type: 10,
          needTotal: true,
          dataIndex: "noTaxAmount"
        },
        {
          title: "税费",
          align: "left",
          width: "80px",
          needTotal: true,
          type: 10,
          dataIndex: "taxAmount"
        },
        {
          title: "3%开票金额",
          align: "left",
          needTotal: true,
          width: "100px",
          type: 10,
          dataIndex: "senondInvoiceAmount"
        },
        {
          title: "3%开票税金",
          align: "left",
          width: "100px",
          needTotal: true,
          type: 10,
          dataIndex: "secondTaxAmount"
        }, {
          title: "创建时间",
          align: "center",
          width: "90px",
          dataIndex: "createTime"
        }, {
          title: "支付日期",
          align: "center",
          width: "90px",
          dataIndex: "payDate"
        }, {
          title: "支付状态",
          align: "center",
          width: "80px",
          fixed: "right",
          dataIndex: "paymentState",
          scopedSlots: { customRender: "paymentState" }
        }, {
          title: "操作",
          align: "center",
          width: "160px",
          dataIndex: "action",
          fixed: "right",
          scopedSlots: { customRender: "action" }
        }
      ],
      operator: operator,
      operator2: operator2
    }
  },
  computed: {
    rowSelection() {
      return {
        getCheckboxProps: record => ({
          props: {
            disabled: record.disabled
          }
        })
      }
    }
  },
  methods: {
    setData(data) {
      if (data && data.paymentId) {
        this.queryParam.settleInvoiceId = data.paymentId
        this.queryParam.invoiceAmount = data.invoiceAmount
        this.queryParam2.paymentId = data.paymentId
        this.$refs["table"].refresh(false)
      }
    },
    onSuccess() {
      this.$refs["settleTable"].refresh(false)
    },
    printOrder(record) {
      this.$refs["printModal"].open(record.paymentId, 2, "Settle")
    },
    /**
     * 查询事件
     * @param searchParams
     */
    searchTable(searchParams) {
      this.queryParam = Object.assign(this.queryParam, searchParams)
      this.$refs.table.refresh(true, searchParams)
    }
  },
  created() {
  }
}
</script>